#!/usr/local/bin/python3

import DLMMessage

class MessageWorker(object):
    def __init__(self, fm):
        self.function_map = fm

    # This method expects a Message object and executes a function
    # provided in the function map passed in on instatiation.
    def do_action(self, msg):
        if '_debug_' not in globals():
            _debug_ = False
            
        if type(msg) == Message:
            cmd = msg.Cmd
            self.function_map[cmd](msg)
            if _debug_:
                print("MessageWorker Command Executed: {0}".format(cmd))
        else:
            if _debug_:
                print(
                    "MessageWorker Error: Incorrect argument type. " /
                    "Expected 'Message', recieved {0}.".format(type(msg))
                )